import type { GoodsDetail } from '@/types/modules/goods';
import { http } from '@/utils/request';
import { defineStore } from 'pinia';
import { ref } from 'vue';

export const useGoodsStore = defineStore('goods', () => {
  const goodsDetail = ref<GoodsDetail>();

  const getGoodsDetail = async (id: string) => {
    // 🐛修复BUG，先清空数据，再请求新数据，否则页面中的 v-if="goodsDetail" 工作异常
    goodsDetail.value = undefined;
    const res = await http<GoodsDetail>('GET', '/goods', { id: id });
    goodsDetail.value = res.data.result;
  };

  return {
    getGoodsDetail,
    goodsDetail,
  };
});
